﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class TblShippToDAO
    {
         private DBService _db = null;
         public TblShippToDAO(string ConnectionString)
         {
            _db = new DBService(ConnectionString);
         }
         public TblShippTo GetAll(int AccountID)
         {
             TblShippTo shippto = new TblShippTo();
             try
             {
                 DataTable dt = _db.ExeSP_DataTable("select * from TblShipTo where AccountID = @AccountID ",
                    new string[] { "@AccountID" },
                    new object[] { AccountID },
                   CommandType.Text);

                 foreach (DataRow dr in dt.Rows)
                 {
                     shippto.AccountID = AccountID;
                     shippto.Address = dr["Address"].ToString();
                     shippto.City = dr["City"].ToString();
                     shippto.ContactName = dr["ContactName"].ToString();
                     shippto.Country = dr["Country"].ToString();
                     shippto.Email = dr["Email"].ToString();
                     shippto.ModifyDate1 = Convert.ToDateTime(dr["ModifyDate"]);
                     shippto.Name = dr["Name"].ToString();
                     shippto.Phone = dr["Phone"].ToString();
                     shippto.Postcode = dr["Postcode"].ToString();
                     shippto.ShippingMethod = dr["ShippingMethod"].ToString();
                     shippto.State = dr["State"].ToString();

                 }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return shippto;
         }
         public bool Update(TblShippTo shipto)
         {
             bool flag = false;
             try
             {
                 int result = 0;
                 result = _db.ExeSP_NonQuery("[sp_ShippingTo_Upd]",
                     new string[] { "@p_AccountID", "@p_Name", "@p_Address","@p_City",
                         "@p_Country", "@p_Phone", "@p_Email", "@p_ContactName", "@p_ShippingMethod" },
                     new object[] { shipto.AccountID, shipto.Name, shipto.Address, shipto.City, shipto.Country, shipto.Phone, shipto.Email,
                         shipto.ContactName, shipto.ShippingMethod},
                     CommandType.StoredProcedure);

                 flag = true;
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return flag;
         }


         //public TblShippTo GetShippingToByAccount(int AccountID)
         //{
         //    TblShippTo shipto = new TblShippTo();
         //    try
         //    {
         //        DataTable dt = _db.ExeSP_DataTable("select * from TblShipTo where AccountID = @AccountID",
         //            new string[] { "@AccountID" },
         //            new object[] { AccountID},
         //            CommandType.Text);
         //        foreach (DataRow dr in dt.Rows)
         //        {
         //            shipto.AccountID = AccountID;
         //            shipto.Name = dr["Name"].ToString();
         //            shipto.Address = dr["Address"].ToString();
         //            shipto.City = dr["Address"].ToString();
         //            shipto.State = dr["State"].ToString();
         //            shipto.Postcode = dr["Postcode"].ToString();
         //            shipto.Country = dr["Country"].ToString();
         //            shipto.Phone = dr["Phone"].ToString();
         //            shipto.Email = dr["Email"].ToString();
         //            shipto.ContactName = dr["Email"].ToString();
         //            shipto.ModifyDate1 = Convert.ToDateTime(dr["ModifyDate"]);
         //            shipto.ShippingMethod = dr["ShippingMethod"].ToString();
         //        }
         //    }
         //    catch (Exception ex)
         //    {
         //        throw ex;
         //    }
         //    return shipto;
         //}
    }
}
